package etc.obu.service.utils;

/*
* 消息序列化
* */
public class ObuSerialization {

    public static byte[]  serialize(String msg){
        return ObuSerialization.toBytes(msg);
    }

    public static Object deSerialize(byte[] bytes,Class clazz){
        return null;
    }

    private static byte[] toBytes(String msg){
        byte[] result=new byte[msg.length()/2];
        int j=0;
        for (int i = 0; i < msg.length(); i+=2) {
            int target = Integer.parseInt(msg.substring(i, i + 2), 16);
            if(target>127){
                target=127-target;
            }
            result[j]=(byte)target;
            j++;
        }
        return result;
    }
}
